<?php
session_start();
include '../defines.php';
autentifikacijaAdmin();

$action = "";

if (!isset($_GET['action'])) myDie("", "index.php");

$action = $_GET['action'];


if (strcmp($action,"new") == 0) {
	if (!isset($_POST['receptNaziv'])) myDie("Informacije o receptu nisu upisane!", "recepti.php");
	
	$values = array();
	$values[0][0] = "naziv"; $values[0][1] = $_POST['receptNaziv'];
	$values[1][0] = "opis"; $values[1][1] = $_POST['receptOpis'];
	$values[2][0] = "reference"; $values[2][1] = $_POST['receptReference'];
	$values[3][0] = "vlasnik"; $values[3][1] = $_POST['receptVlasnik'];
	
	dbInsert("recepti", $values, 4);
	header("Location: ../recepti.php?action=pretraga");
}
else if (strcmp($action, "edit") == 0) {
	if (!isset($_GET['id'])) myDie("Recept za promjenu nije odabran","recepti.php");
	if (!isset($_POST['receptNaziv'])) myDie("Informacije o receptu nisu upisane!", "recepti.php");
	
	$id = $_GET['id'];
	$values = array();
	$values[0][0] = "naziv"; $values[0][1] = $_POST['receptNaziv'];
	$values[1][0] = "opis"; $values[1][1] = $_POST['receptOpis'];
	$values[2][0] = "reference"; $values[2][1] = $_POST['receptReference'];
	$values[3][0] = "vlasnik"; $values[3][1] = $_POST['receptVlasnik'];
	
	dbUpdate("recepti", $values, 4, $id);
	header("Location: ../recepti.php?action=pretraga");
}
else if (strcmp($action, "delete") == 0) {
	if (!isset($_GET['id'])) 
	myDie("Nije odabran recept za brisanje!", "recepti.php");

	$id = $_GET['id'];
	dbDelete("recepti", $id);
	header("Location: ../recepti.php?action=pretraga");
}
else {

}